<template>
    <h2>会员权益显示页面</h2>  
    权限名称<input type="text" v-model="page.MRname" />

    当前页<input type="text" v-model.number="page.index" />
    共<span>{{ pageTotal.pcount }}</span>页
    页容量<input type="text"  v-model.number="page.size" />
    <input type="button" value="添加" @click="addRight"/>
    <input type="button" value="查询" @click="loadData"/>
   <table border="1">
    <thead>
        <tr>
        <td>权限编号</td>
        <td>权限名称</td>
        <td>权限说明</td>
        <td>权限是否自定义</td>
        <td>权限类型</td>
        <td>权限规则</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
        <tr v-for="item in member" :Key="item.MR_Id">
        <td>{{item.MR_Id}}</td>
        <td>{{item.MR_Name}}</td>
        <td>{{item.MR_Info}}</td>
        <td>{{ item.MR_IsCustom==true?"是":"否" }}</td>
        <td>{{item.MR_RuleType}}</td>
        <td>{{item.MR_Rule}}</td>
        <td>
            <input type="button" value="删除" @click="delRight(item.MR_Id)"/>
            <input type="button" value="编辑" @click="editRight(item.MR_Id)"/>
        </td>
    </tr>
    </tbody>
   </table>
</template>

<script setup lang="ts">
    import {ref,onMounted,computed} from 'vue'
    import {useRoute} from 'vue-router'
    import {useRouter} from 'vue-router'
    const router=useRouter();
    const route=useRoute();
    import axios from 'axios'
    const editRight=(MRid:string)=>{
        router.push({
            name:"EditRight",
            params:{
                mRid:MRid
            }
        })
    }


    const delRight=(MRid:string)=>{
       if(confirm('确定删除吗'))
       {
        axios.delete('https://localhost:44320/api/Member/RightDel',{
            params:{
                MTname:"管理员",
                MRid:MRid
            }
        })
        .then(res=>{
            if(res.data>0)
            {
                alert('删除成功');
                loadData();
            }
            else
            {
                alert('删除失败');
            }
        })
       }
    }


    const member=ref([{
      "MR_Id": "",
      "MR_Name": "",
      "MR_Info": "",
      "MR_IsCustom": false,
      "MR_RuleType": 0,
      "MR_Rule": ""
    }])
onMounted(()=>{
    loadData();
})

const pageTotal=ref({
    pcount:0
});

const page=ref({
    count:0,
    index:1,
    size:2,
    MRname:""
})
const loadData=()=>{
    console.log(page.value.MRname);
    axios.get('https://localhost:7120/api/Member/RightShow',{
        params:{
            index:page.value.index,
            size:page.value.size,
            MRname:page.value.MRname,            
        }
    })
    .then(res=>{
        console.log(res.data);
        page.value.count=res.data.count;
        member.value=res.data.data;
        pageTotal.value.pcount=Math.ceil(page.value.count/page.value.size);
        console.log(pageTotal.value.pcount);
    })
}



const addRight=()=>{
    router.push('/addRight');
}

</script>